package com.pcbly.web.components.utils.jfreechart;

import java.awt.Color;
import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.Year;
import org.jfree.data.xy.XYDataset;

public class MutiTimeLineChart  extends AbstractChartFont {
	/**
	 * 构造数据集
	 * 
	 * @return
	 */
	public  XYDataset getDataSet() {
		String tag1 = "地区1";
		TimeSeries timeSer1 = new TimeSeries(tag1, Year.class);
		timeSer1.add(new Year(2000), 1000);
		timeSer1.add(new Year(2001), 1300);
		timeSer1.add(new Year(2002), 1700);
		timeSer1.add(new Year(2003), 1900);
		timeSer1.add(new Year(2004), 1400);
		timeSer1.add(new Year(2005), 2000);
		timeSer1.add(new Year(2006), 2200);
		timeSer1.add(new Year(2007), 1800);
		timeSer1.add(new Year(2008), 2300);
		timeSer1.add(new Year(2009), 1900);

		String tag2 = "地区2";
		TimeSeries timeSer2 = new TimeSeries(tag2, Year.class);
		timeSer2.add(new Year(2000), 900);
		timeSer2.add(new Year(2001), 1100);
		timeSer2.add(new Year(2002), 1300);
		timeSer2.add(new Year(2003), 1400);
		timeSer2.add(new Year(2004), 1700);
		timeSer2.add(new Year(2005), 1000);
		timeSer2.add(new Year(2006), 1300);
		timeSer2.add(new Year(2007), 2300);
		timeSer2.add(new Year(2008), 2700);
		timeSer2.add(new Year(2009), 1900);
		
		TimeSeriesCollection timeSerCollection = new TimeSeriesCollection();
		timeSerCollection.addSeries(timeSer1);
		timeSerCollection.addSeries(timeSer2);
		return timeSerCollection;
	}
	/**
	 * 根据数据集创建图表对象
	 * 
	 * @param categoryDataset
	 * @return
	 */
	public  JFreeChart createJFreeChart(XYDataset xyDataset) {
		StandardChartTheme standardChartTheme = new StandardChartTheme("name");
		standardChartTheme.setLargeFont(new Font("宋体",Font.BOLD, 10));//可以改变轴向的字体
		standardChartTheme.setRegularFont(new Font("宋体",Font.BOLD, 15));//可以改变图例的字体
		standardChartTheme.setExtraLargeFont(new Font("宋体",Font.BOLD, 24));//可以改变图标的标题字体
		ChartFactory.setChartTheme(standardChartTheme);
		JFreeChart chart = ChartFactory.createTimeSeriesChart(
				"地区1和地区2  2000年-2009年年降水量曲线图", "年份", "降水量(mm)", xyDataset, true,
				true, false);
		chart.setBackgroundPaint(Color.WHITE);
		return chart;
	}
	
	public JFreeChart index(){
		XYDataset dataset=getDataSet();
		return createJFreeChart(dataset); 
	}
}
